<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/2 0002
 * Time: 12:18
 */

namespace app\admin\controller;
use app\common\controller\AdminBase;
use think\db;
use think\Session;

class ContestantReview extends AdminBase
{

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     *   选手列表
     *
     * */
    public function contestantReview($keyword = '', $page = 1){
        if($page != 1){
            if($keyword == null){
                $keyword = Session::get('keyword');
            }
        }
        $map = [];
        if ($keyword) {
            $map['playerName|playerMobile|openId'] = ['=', "{$keyword}"];
        }
        $player_list = Db::table('vote_player')->where($map)->where(['status'=>0])->order('ID DESC')->paginate(15, false, ['page' => $page]);

        return $this->fetch('contestantReview',['keyword' => $keyword,'player_list'=>$player_list]);
    }


    /**
     *   选手审核
     *
     **/
    public function toExamine(){
        $id = $this->request->param('id');
        $status = $this->request->param('status');
        $success = null;
        if($status == 1){
           $result = Db::table('vote_player')->where(['id'=>$id])->update(['status'=>1]);
        }
        if($status == 0){
            $result = Db::table('vote_player')->where(['id'=>$id])->update(['status'=>2]);
        }
        if($result == 1){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }

    }


    /**
     *  选手删除
     *
     **/
    public function delete(){
        $id = $this->request->param('id');
        $result = Db::table('vote_player')->where(['id'=>$id])->delete();
        if ($result > 0) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }



}